package io.kiki.sba.registry.remoting.netty;


import io.kiki.sba.registry.api.ChannelHandler;
import io.kiki.stack.netty.processor.BizContext;
import io.kiki.stack.netty.userProcessor.SyncUserProcessor;

import java.util.concurrent.Executor;


public class SyncUserProcessorAdapter extends SyncUserProcessor {

    private final ChannelHandler userProcessorHandler;


    public SyncUserProcessorAdapter(ChannelHandler userProcessorHandler) {
        this.userProcessorHandler = userProcessorHandler;
    }


    @Override
    public Object syncHandleRequest(BizContext bizContext, Object object) throws Exception {
        Channel channel = new Channel(bizContext.getChannel());
        return userProcessorHandler.messageReply(channel, object);
    }

    @Override
    public String interest() {
        if (userProcessorHandler.interest() != null) {
            return userProcessorHandler.interest().getName();
        }

        return null;
    }

    @Override
    public Executor getExecutor() {
        return userProcessorHandler.getExecutor();
    }
}
